﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Base;
using ERP.BusinessEntities;
using System.Windows.Forms;
using System.IO;
using Core;
using System.Data;

namespace MainApp.Modules.Employee
{
    public class EmployeeModule: BaseModule
    {
        public EmployeeModule()
        {
            this.Name = "Employee";
            entity = new EmployeeEntity();
            Init();
        }

        public override void ActionSave()
        {
            HREmployeesInfo emp = (HREmployeesInfo)entity.MainObject;
            base.ActionSave();
        }

        public override void Import()
        {
            //OpenFileDialog openFileDlg = new OpenFileDialog();
            //openFileDlg.Multiselect = false;
            //openFileDlg.ShowDialog();

            //String strFileName = openFileDlg.FileName;

            //if (File.Exists(strFileName) == false) return;

            //ExcelClient exClient = new ExcelClient(strFileName);
            //exClient.OpenConnection();
            //String[] lstSheets = exClient.GetSheetName();
            //DataTable dt = exClient.GetAllDataFromSheet(lstSheets[0]);
            //foreach (DataRow dr in dt.Rows)
            //{
            //    try
            //    {
            //        HREmployeesInfo Employee = new HREmployeesInfo();
            //        Employee.No = Convert.ToString(dr[0]);
            //        Employee.Name = Convert.ToString(dr[3]);
            //        Employee.Desc = Employee.Name;
            //        if(dr[4] != null && dr[4] != DBNull.Value)
            //            Employee.StartupDate = Convert.ToDateTime(dr[4]);

            //        String strSector = Convert.ToString(dr[5]);
            //        HREmployeeSectorsInfo Sector = AppContext.EmployeeSectorCtrl.GetObjectByNo(strSector);
            //        if (String.IsNullOrEmpty(strSector) == false)
            //        {
            //            if (Sector == null)
            //            {
            //                Sector = new HREmployeeSectorsInfo();
            //                Sector.No = strSector;
            //                Sector.Name = strSector;
            //                Sector.Desc = strSector;

            //                Sector.ID = AppContext.EmployeeSectorCtrl.CreateObject(Sector);
            //            }
            //        }

            //        String strSubSector = Convert.ToString(dr[6]);
            //        HREmployeeSectorsInfo SubSector = AppContext.EmployeeSectorCtrl.GetObjectByNo(strSubSector);
            //        if (String.IsNullOrEmpty(strSubSector) == false)
            //        {
            //            if (SubSector == null)
            //            {
            //                SubSector = new HREmployeeSectorsInfo();
            //                SubSector.No = strSubSector;
            //                SubSector.Name = strSubSector;
            //                SubSector.Desc = strSubSector;
            //                if(Sector != null)
            //                    SubSector.FK_HREmployeeSectors_ParentID = Sector.ID;
            //                SubSector.ID = AppContext.EmployeeSectorCtrl.CreateObject(SubSector);
            //            }
            //        }

            //        if(SubSector != null)
            //            Employee.FK_HREmployeeSectors_ID = SubSector.ID;

            //        Employee.CreatedDate = DateTime.Now;
            //        Employee.UpdatedDate = DateTime.Now;


            //        AppContext.EmployeeCtrl.CreateObject(Employee);
            //    }
            //    catch (Exception)
            //    {

            //    }

            //}

        }

    }
}
